/**
 **************************************************************************************************************************
 * 
 **************************************************************************************************************************
 * @file RBAssert.h
 **************************************************************************************************************************/


#ifndef __RBASSERT_H__
#define __RBASSERT_H__


/**************************************************************************************************************************
 * Includes
 **************************************************************************************************************************/

#include "Foundation/Platform/Types.h"
#include "RBMemoryManagerOff.h"
#include <assert.h>
#include "RBMemoryManagerOn.h"

#include "RBString.h"
#include <string>

#if _DEBUG
#define RBAssert(cond, message) RBAssertion::Assert(!!(cond), _CRT_WIDE(__FILE__), __LINE__, message)
#else
#define RBAssert(cond, message)((void)0)
#endif

#define RBCompileAssert(cond) typedef char __RB_COMPILE_ASSERT__[(cond)?1:-1]


#if _DEBUG
namespace RBAssertion
{
    static inline void Assert(bool bCondition, const wchar_t* pcFile, uint32 iLine, const RBString& strMessage)
    {
        if (!bCondition)
        {
            size_t sizewChar = 0;
            wchar_t* pwcMessage = new wchar_t[strMessage.size()+1];
            mbstowcs_s(&sizewChar, pwcMessage, strMessage.size()+1, strMessage.c_str(), _TRUNCATE);
            pwcMessage[strMessage.size()] = 0;
            _wassert(pwcMessage, pcFile, iLine);
            delete[] pwcMessage;
        }
    }
}
#endif

/**************************************************************************************************************************/

#endif // __RBASSERT_H__
